package com.wanmait.baohan.service.Impl;

import com.github.pagehelper.PageInfo;
import com.wanmait.baohan.mapper.BookingTicketApplicationMapper;
import com.wanmait.baohan.mapper.TicketApprovalMapper;
import com.wanmait.baohan.pojo.Staff;
import com.wanmait.baohan.pojo.TicketApproval;
import com.wanmait.baohan.service.TicketApprovalService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * TODO
 *
 * @author 打豆豆
 * @version 1.0
 * @date 2021/1/4 0:14
 * @description:
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class TicketApprovalServiceImpl implements TicketApprovalService {

    @Resource
    private TicketApprovalMapper ticketApprovalMapper;

    @Resource
    private HttpServletRequest request;

    @Resource
    private BookingTicketApplicationMapper bookingTicketApplicationMapper;

    @Override
    public void insert(TicketApproval object) {

    }

    @Override
    public void delete(Integer id) {

    }

    @Override
    public void delete(String ids) {

    }

    @Override
    public void update(TicketApproval object) {

    }

    @Override
    public TicketApproval findById(Integer id) {
        return ticketApprovalMapper.selectByBookingTicketApplicationId(id);
    }

    @Override
    public List<TicketApproval> findAll() {
        return null;
    }

    @Override
    public List<TicketApproval> findAll(TicketApproval object) {
        return null;
    }

    @Override
    public PageInfo<TicketApproval> findPage(int pageNum) {
        return null;
    }

    @Override
    public PageInfo<TicketApproval> findPage() {
        return null;
    }

    @Override
    public PageInfo<TicketApproval> findPage(int pageNum, TicketApproval object) {
        return null;
    }

    @Override
    public PageInfo<TicketApproval> findPage(TicketApproval object) {
        return null;
    }

    @Override
    public void submitApprove(TicketApproval ticketApproval) {
        Staff user = (Staff)request.getSession().getAttribute("user");
        ticketApproval.setStaff(user);
        ticketApproval.setApprovalTime(new Date());
        ticketApprovalMapper.insert(ticketApproval);
        bookingTicketApplicationMapper.updateState(ticketApproval.getBookingTicketApplicationId(), ticketApproval.getState());
    }
}
